//# sourceURL=dynamicScript.js
$ ( function () {
    selectByPrimaryKeyfhcx()
})

function selectByPrimaryKeyfhcx() {
    $("#tabscx").bootstrapTable({
        //请求方式  get请求中文会乱码，建议使用post请求
        method: 'post',
        //请求头部的设置
        contentType: 'application/json',
        //url
        url: '/selectByPrimaryKeyfhcx',
        //设置交替行样式
        striped: true,
        //初始显示页号
        pageNumber: 1,
        //设置表格高度
        //height: 350,
        //是否显示分页
        pagination: true,
        //设置是服务端分页还是客户端分页
        sidePagination: 'server',
        //页大小
        pageSize: 3,
        //分页列表
        pageList: [3, 5, 6, 10],
        //上传到服务端的参数
        queryParams:function (parms) {
            return{
                num:(parms.offset/parms.limit)+1,
                size:parms.limit,
            }
        },
        //定义列名
        columns:[
            {title:"产品编号",field:"prouctid",align:"center"},
            {title:"产品名称",field:"prouctname",align:"center"},
            {title:"用途类型",field:"type",align:"center"},
            {title:"单位",field:"amountunit",align:"center"},
            {title:"成本单价",field:"realcostprice",align:"center"},
            {title:"出库",field:"checktag",align:"center",
                formatter:function (vale,row,index) {
                    let pro = JSON.stringify(row);
                    let del_btn="<input type='button' class=\"btn btn-success\" onclick=\'rk("+pro+")\' value='出库'>\n";
                    return del_btn;
                }},
        ]
    })
}
function rk(pro) {
    let id = pro.prouctid;
    let num1=[];
    $("#demoer tr").each(function (i) {
        num1= $(this).children('td').eq(2).find("input").val();
        if (id==num1){
            $(this).remove()
        }
    })
    let cc=" <tr>\n" +
        " <td><input name='ckb' type='checkbox'></td>\n" +
        " <td><input name='prouctname' readonly style='border: none;outline: none;width: 100px' value='"+pro.prouctname+"'></td>\n" +
        " <td><input name='prouctid' readonly style='border: none;outline: none;width: 100px' value='"+pro.prouctid+"'></td>\n" +
        " <td><input name='productdescribe' readonly style='border: none;outline: none;width: 60px' value='"+pro.productdescribe+"'></td>\n" +
        " <td><input name='amount' id='amount' style='border: none;outline: none;width: 50px' value='1'></td>\n" +
        " <td><input name='amountunit' readonly style='border: none;outline: none;width: 60px' value='"+pro.amountunit+"'></td>\n" +
        " <td><input name='costprice' id='realcostprice' readonly style='border: none;outline: none;width: 50px' value='"+pro.realcostprice+"'></td>\n" +
        " <td><input name='subtotal' id='xiaoji' readonly style='border: none;outline: none;width: 100px'></td>\n" +
        " </tr>"
    document.getElementById("demoer").innerHTML+=cc;
}
function yl() {
    document.getElementById("a").style.display ='none';
    document.getElementById("b").style.display = '';
    let count=0;
    let cnum=[];
    $("#demoer tr").each(function (i) {
        let num1= $(this).children("td").eq(4).find("input").val();
        let num2= $(this).children("td").eq(6).find("input").val();
        cnum.push(num1)
        $(this).children("td").eq(7).find("input").val(parseInt(num1)*parseInt(num2))
    })
    let snum=[]
    $("#demoer tr").each(function (i) {
        let a = $(this).children("td").eq(7).find("input").val()
        snum.push(a)
    })
    let cc=0;
    for(let i=1;i<snum.length;i++){
        cc+=parseInt(snum[i])
    }
    for(let i=1;i<cnum.length;i++){
        count+=parseInt(cnum[i])
    }
    $("#zjs").val(count)
    $("#zje").val(cc)
}
function del() {
    let a = $("input:checkbox[name='ckb']:checked").length;
    if(a==0){
        alert("请选中一条数据");
        return;
    }
    var check=$("input[type=checkbox]");
    for (var i=check.length-1; i>=0; i--) {
        if (check[i].checked) {
            check[i].parentNode.parentNode.parentNode.removeChild(check[i].parentNode.parentNode);
        }
    }
}

function qd() {
    let id ='';
    let gatherid='';
    let storer = $("#storer").val();
    let reason = $("#reason").val();
    let amountsum = $("#zjs").val();
    let costpricesum = $("#zje").val();
    let register = $("#register").val();
    let remark = $("#remark").val();
    let Spay ={storer:storer,reason:reason,amountsum:amountsum,costpricesum:costpricesum,register:register,remark:remark};
    console.log(Spay)
    $.ajax({
        type:"post",
        contentType:'application/json',
        url:"../insertre",
        data:JSON.stringify(Spay),
        success:function (data) {
            insertsgd();
        }
    })



}

function insertsgd() {
    let spaydetails=[]
    $("#demoer tr").each(function (i) {
        let prouctname= $(this).children("td").eq(1).find("input").val();
        let prouctid= $(this).children("td").eq(2).find("input").val();
        let productdescribe= $(this).children("td").eq(3).find("input").val();
        let amount= $(this).children("td").eq(4).find("input").val();
        let amountunit= $(this).children("td").eq(5).find("input").val();
        let costprice= $(this).children("td").eq(6).find("input").val();
        let subtotal= $(this).children("td").eq(7).find("input").val();
        let rk={
            productname:prouctname,
            productid:prouctid,
            productdescribe:productdescribe,
            amount:amount,
            amountunit:amountunit,
            costprice:costprice,
            subtotal:subtotal
        }
        spaydetails.push(rk)
    })
    spaydetails.shift()
    $.ajax({
        type:"post",
        contentType:'application/json',
        url:"../insertres",
        data:JSON.stringify(spaydetails),
        success:function (data) {
            if (data==1){
                location.href="../rkre";
            }
        }
    })
}
